#ifndef INCLUDE_PBUFFER_UTILS_H
#define INCLUDE_PBUFFER_UTILS_H

#include <AGL/agl.h>
#include <OpenGL/OpenGL.h>

enum EPBufferFlags
{
	ePBufferFlag_ZBuffer=(1<<0),
};

typedef struct PetePBuffer_tag {
	CGLPBufferObj pbuffer;
	CGLContextObj pbufferContext;
	CGLContextObj previousContext;
	int width;
	int height;
	GLuint textureID;
	bool needsClearing;
	bool needsFlush;
	int createdWidth;
	int createdHeight;
	GLuint target;
	GLuint texFormat;
} PetePBuffer;

PetePBuffer* PBuffer_Create(CGLContextObj sharedContext, int nWidth,
		int nHeight, int colorDepth, int flags);
void PBuffer_Destroy(PetePBuffer* pbuffer);

// Surround rendering with these to draw into the pbuffer, they handle pushing and popping the old
// context for you
void PBuffer_Begin(PetePBuffer* pbuffer);
void PBuffer_End(PetePBuffer* pbuffer);

// Binds the pbuffer as a texture
void PBuffer_SetTexture(PetePBuffer* pbuffer);
void PBuffer_Use(PetePBuffer* pbuffer);

#endif // INCLUDE_PBUFFER_UTILS_H
